var events = require('events'),
  eventEmitter = new events.EventEmitter();

var listener1 = function () {
  console.log('listener1 执行');
};

var listener2 = function () {
  console.log('listener2 执行');
};

var listener3 = function() {
  console.log('onec Listener 执行');
};

eventEmitter.on('connection',listener1);
eventEmitter.addListener('connection',listener2);
eventEmitter.once('connection',listener3);

eventEmitter.emit('connection');

console.log('\r');
eventEmitter.removeListener('connection', listener1);
eventEmitter.emit('connection'); //测试onceListener和removeListener

console.log(eventEmitter.listenerCount('connection'));

// 打开会抛出异常
// eventEmitter.emit('error');
